
$(function(){
    $('#selectedRecord').bootstrapTable({
        url: '/RecordManager/selectRecord',
        method: 'get',
        showRefresh: true,  //显示刷新按钮
        search: true,
        toolbar:'#toolbar',
        striped : true,     //设置为true会有隔行变色效果
        //sidePagination:'server',//服务器端分页默认接受rows和total
        pagination:true,//客户端分页
        sidePagination:'client',
        idFiled:'user_name',
        pageNumber:1,
        pageSize:10,
        columns: [
            {
                field: 'checkId',
                checkbox:true,
                clickToSelect:true
            }, {
                field: 'userid',
                visible: false
            },{
                field: 'user_name',
                title: '用户名'
            }
            , {
                field: 'position_name',
                title: '所属岗位'
            },{
                field: 'position_id',
                visible: false
            },{
                field: 'institution_name',
                title: '所属机构'
            },{
                field: 'institution_id',
                visible: false
            },{
                field: 'salary',
                title: '工资'
            },{
                field: 'salary_id',
                visible: false
            },{
                field: 'education_desc',
                title: '学历'
            },{
                field: 'education_id',
                visible: false
            },{
                field: 'record_id',
                visible: false
            }

            ]
    });
});

var vm = new Vue({
    el:'#SelectRecord',
    data:{
        showList:1,
        userName2:'',
        institutionRecord:'',
        positionRecord:'',
        salaryRecord:'',
        educationRecord:'',
        record:{educationId:'',educationId:'',recordId:''},
        position:{positionId:''}
    },
    methods: {
        // //***start选课的方法***
        // //选课按钮
        upd: function () {
            // 弹出选课对话框

            var rows = $("#selectedRecord").bootstrapTable('getSelections');
            if (rows.length != 1) {
                layer.alert('请选择一条记录');
                return;
            } else {
                $('#updRecord').modal("show");
                vm.userName2=rows[0].user_name;
                vm.salaryRecord=rows[0].salary;
                vm.institutionRecord=rows[0].institution_name;
                $("#positionRecord").empty();
                var optionName="请点击选择";
                $.ajax({
                    type:"GET",
                    url:"/PositionManager/selectPosition",
                    success:function (result) {

                        $("#positionRecord").append("<option value=" + rows[0].position_id + ">" + rows[0].position_name + "</option>")
                        for(var i =0;i<result.length;i++){
                            if(result[i]['position_id']!=rows[0].position_id){
                                $("#positionRecord").append("<option value="+result[i]['position_id'] + ">" +result[i]['name'] + "</option>");
                            }
                        }

                    }
                });
                var pId;
                //回显教师姓名
                //下拉框点击事件
                $("#positionRecord").change(function() {
                    pId = $("#positionRecord option:selected").val();
                    vm.position.positionId=pId;
                    $.ajax({
                        type: "POST",//post方法默认是表单数据提交，用requestParameter接收，如果要用jason需要配置在conmmon.js中的第一行有配置
                        url: "/PositionManager/selectPositionById",
                        data: JSON.stringify(vm.position),//参数

                        success: function (result) {

                            if (result) {
                                vm.institutionRecord = result[0]['name'];
                                vm.salaryRecord=result[0]['salary'];
                            } else {
                                layer.alert("有错");
                            }
                        }
                    });
                });
                    $("#educationRecord").empty();
                    var optionName = "请点击选择";
                    $.ajax({
                        type: "GET",
                        url: "/EducationManager/selectEducation",
                        success: function (result) {

                            $("#educationRecord").append("<option value=" + rows[0].education_id + ">" + rows[0].education_desc + "</option>")
                            for (var i = 0; i < result.length; i++) {
                                if (result[i].educationId != rows[0].education_id) {
                                    $("#educationRecord").append("<option value=" + result[i].educationId + ">" + result[i].educationDesc + "</option>");
                                }
                            }

                        }
                    });
                }

        },
        submit2: function () {

            var rows = $("#selectedRecord").bootstrapTable('getSelections');
            var positionId=$("#positionRecord option:selected").val();
            var educationId=$("#educationRecord option:selected").val();

            vm.record.recordId=rows[0].record_id;
            vm.record.positionId=positionId;
            vm.record.educationId=educationId;

            $.ajax({
                type: "POST",//post方法默认是表单数据提交，用requestParameter接收，如果要用jason需要配置在conmmon.js中的第一行有配置
                url: '/RecordManager/updPositionById',//请求的controller
                data: JSON.stringify(vm.record),//参数
                success: function (r) {
                    if (r === true) {
                        layer.alert('修改成功');
                        vm.record.educationId=null;
                        $('#selectedPosition').bootstrapTable('refresh');
                    }
                },
                error: function () {
                    layer.alert('失败');
                }
            });
        },
        excel:function () {
            var form = $("<form method='post'></form>");
            form.attr("action","/RecordManager/ExcelRecord");
            $("body").append(form);
            form.submit();
            form.remove();
        }

        // //***end选课的方法***
        //

    }
    //***end实验的方法***

});
